package com.ruoyi.web.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.web.service.DemoCustomerService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.DemoCustomer;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 顾客Controller
 *
 * @author pei
 * @date 2024-06-02
 */
@RestController
@RequestMapping("/customer/customer")
public class DemoCustomerController extends BaseController
{
    @Autowired
    private DemoCustomerService demoCustomerService;

    /**
     * 查询顾客列表
     */

    @GetMapping("/list")
    public TableDataInfo list(DemoCustomer demoCustomer)
    {
        startPage();
        List<DemoCustomer> list = demoCustomerService.selectDemoCustomerList(demoCustomer);
        return getDataTable(list);
    }

    /**
     * 导出顾客列表
     */

    @Log(title = "顾客", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DemoCustomer demoCustomer)
    {
        List<DemoCustomer> list = demoCustomerService.selectDemoCustomerList(demoCustomer);
        ExcelUtil<DemoCustomer> util = new ExcelUtil<DemoCustomer>(DemoCustomer.class);
        util.exportExcel(response, list, "顾客数据");
    }

    /**
     * 获取顾客详细信息
     */

    @GetMapping(value = "/{cId}")
    public AjaxResult getInfo(@PathVariable("cId") Long cId)
    {
        return success(demoCustomerService.selectDemoCustomerByCId(cId));
    }

    /**
     * 新增顾客
     */

    @Log(title = "顾客", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DemoCustomer demoCustomer)
    {
        return toAjax(demoCustomerService.insertDemoCustomer(demoCustomer));
    }

    /**
     * 修改顾客
     */

    @Log(title = "顾客", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DemoCustomer demoCustomer)
    {
        return toAjax(demoCustomerService.updateDemoCustomer(demoCustomer));
    }

    /**
     * 删除顾客
     */

    @Log(title = "顾客", businessType = BusinessType.DELETE)
    @DeleteMapping("/{cIds}")
    public AjaxResult remove(@PathVariable Long[] cIds)
    {
        return toAjax(demoCustomerService.deleteDemoCustomerByCIds(cIds));
    }
}
